import type { RouteRecordRaw } from 'vue-router'

interface RouteConfig {
  meta?: Record<string, unknown>
  [key: string]: unknown
}

export function generateRoutes() {
  const routes: RouteRecordRaw[] = []
  const modules = import.meta.glob('/src/views/**/index.vue')
  const configs = import.meta.glob('/src/views/**/routerConfig.ts', { eager: true })

  for (const path in modules) {
    const dirName = path.split('/')[3]
    const configPath = `/src/views/${dirName}/routerConfig.ts`

    const config = (configs[configPath] as any)?.default || {} as RouteConfig

    routes.push({
      path: `/${dirName}`,
      name: dirName,
      component: modules[path],
      ...config
    })
  }
  console.log(routes)
  return routes
}
